<template>
  <div class="customerStatistics">
    <div class="title">SOP回复率<span class="icon">指标说明</span>
      <div class="time">更新时间：2024-04-09 02:42:20</div>
    </div>
    <div class="formGroup">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="90px" class="">
        <el-form-item prop="userName2">
          <div class="search">
            <el-input v-model="queryParams.userName1" size="small" placeholder="搜索模版名称" clearable/>
            <el-button icon="el-icon-search" size="small" @click="handleQuery"></el-button>
          </div>
        </el-form-item>
        <el-form-item prop="userName2">
          <multipleWeChat :options="options" @getValue="getValue" :placeholderText="`全部企微号`"></multipleWeChat>
        </el-form-item>
        <el-form-item prop="userName2">
          <el-select v-model="queryParams.userName2" size="small"  style="width: 100px" filterable placeholder="请选择类型" @change="handleQuery">
            <el-option
              v-for="item in modelList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="userName2" style="margin-left: -10px">
          <el-select v-model="queryParams.userName2" size="small" filterable placeholder="请选择类型" @change="handleQuery">
            <el-option
              v-for="item in modeAllList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="userName2">
          <div class="search">
            <el-input v-model="queryParams.userName1" size="small" placeholder="规则id" clearable/>
            <el-button icon="el-icon-search" size="small" @click="handleQuery"></el-button>
          </div>
        </el-form-item>
        <el-form-item prop="userName2">
          <el-select v-model="queryParams.userName2" size="small" filterable placeholder="请选择类型" @change="handleQuery">
            <el-option
              v-for="item in typeList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建日期：" prop="userName2">
          <div class="time-big">
            <el-date-picker
              size="small"
              v-model="timeRange"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </div>

        </el-form-item>
      </el-form>
      <el-button plain class="exportData" size="small">导出数据</el-button>
    </div>
    <div class="tableAnalysis">
      <el-table
        :data="tableDataList"
        ref="customerMgtList"
      >
        <el-table-column
          :label="item.label"
          align="center"
          v-for="(item, index) in tableColumns"
          :key="index"
          :prop="item.key"
          :min-width="item.minWidth ? item.minWidth : ``"
          :fixed="item.fixed ? item.fixed : false"
          :show-overflow-tooltip="true"
        >
          <!--用于表格自定义-->
          <template slot="header" v-if="item.showHeaderTip">
            <div>
              {{ item.label }}
              <el-tooltip effect="dark" :content="item.showHeaderTip" placement="top">
                <span><i class="el-icon-question"></i></span>
              </el-tooltip>
            </div>
          </template>
          <template slot-scope="scope">
            <div>{{ scope.row[item.key] }}</div>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="220">
          <template slot-scope="scope">
            <el-button @click="handleView(scope.row)" type="text" size="small">分日数据</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <SOPsessionDetails v-if="showSessionDetails" :visableIf.sync="showSessionDetails"></SOPsessionDetails>
  </div>
</template>
<script>
import {listUser} from "@/api/system/user";
import {getTime} from "@/utils";

export default {
  name: "privateChatResponseRate",
  components: {
    'multipleWeChat': () => import('@/views/components/multipleWeChat.vue'),
    'SOPsessionDetails': () => import('./SOPsessionDetails.vue'),
  },
  data() {
    return {
      showSessionDetails: false,
      queryParams: {},
      timeRange: [],
      options: [{
        value: 1,
        label: '小红',
        WeChatNum: 2,
        WeChatName: '智行',
      }, {
        value: 2,
        label: '小军',
        WeChatNum: 1,
        WeChatName: '锐行',
      }, {
        value: 3,
        label: '小李',
        WeChatNum: 1,
        WeChatName: '锐行',
      }],
      sexList: [
        {value: 1000, name: '男',},
        {value: 1200, name: '女',},
      ],
      typeList: [
        {value: '1', label: '标准SOP'},
        {value: '2', label: '标签SOP'},
        {value: '3', label: '新客户SOP'},
      ],
      modelList: [
        {value: '1', label: '企业模版'},
        {value: '2', label: '个人模板'},
      ],
      modeAllList: [
        {value: '1', label: '模版一'},
        {value: '2', label: '模版二'},
      ],
      selectedRange: 'today',
      tableHeight: 600,
      tableColumns: [
        {key: 'name', label: `规则ID`, visible: true, minWidth: 150, fixed: true},
        {key: 'mobile', label: `模板名称`, visible: true, minWidth: 150, fixed: false,},
        {key: 'email', label: `类型`, visible: true, minWidth: 200,},
        {key: 'last_login_time', label: `对象数`, visible: true, minWidth: 200, showHeaderTip: '已触发该任务的对象总数',},
        {key: 'create_time', label: `平均回复率`, visible: true, minWidth: 200, showHeaderTip: '已发送对象中回复率平均数，每个对象每日发的消息中，任意一条在统计时效内有回复即算已回复；',},
        {key: 'check_payCreate_time', label: `平均流失率`, visible: true, minWidth: 200, showHeaderTip: '已发送对象中流失率平均数，每个对象每日发的消息中，每条发送后在统计时效内流失的客户算流失，不在统计时效内流失的不计入；',},
        {key: 'check_payCreate_time', label: `企微号`, visible: true, minWidth: 200,},
        {key: 'check_payCreate_time', label: `创建时间`, visible: true, minWidth: 200,},
        {key: 'check_payCreate_time', label: `统计时效（分）`, visible: true, minWidth: 200,showHeaderTip: '每个任务设置的统计时效；'},
      ],
      tableDataList: [],
      total: 8, // 表格的总条数
    }
  },
  watch: {},
  computed: {
  },
  created() {
    //this.getList();
    this.tableDataList = [];
     for (let i=0 ;i<3;i++){
       let obj={
         name:'2023-12-12',
         mobile:0,
         email:0,
         last_login_time:0,
         create_time:0,
         check_payCreate_time:0,
       }
       this.tableDataList.push(obj);
     }
  },
  methods: {
    getValue(obj) {
      console.log('获取行', obj);
    },
    handleView() {
      this.showSessionDetails = true;
    },
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.tableDataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
  },
}
</script>


<style scoped lang="scss">
.title {
  display: flex;
  align-items: center;
  padding: 16px 0 0;
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 15px;
  position: relative;

  .icon {
    font-size: 12px;
    font-weight: 400;
    color: #3070ff;
    margin-left: 10px;
  }

  .time {
    position: absolute;
    right: 0px;
    top: 10px;
    color: #8C8C8C;
    font-size: 12px;
    font-weight: 400;
  }
}

.timeType {
  display: flex;
  align-items: center;
  margin-right: 10px;

  li {
    border: 1px solid #eee;
    height: 32px;
    margin: 0;
    padding: 0 15px;
    list-style: none;
    cursor: pointer;

    &.active {
      border-color: #2d8cf0;
      color: #2d8cf0;
    }
  }
}

.time-big {
  display: flex;
  align-items: center;
}

.formGroup {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  width: 100%;
}

.center-title {
  height: 30px;
  display: flex;
  align-items: center;

  span {
    content: "";
    width: 4px;
    height: 14px;
    background-color: #3070ff;
    display: block;
    margin-right: 5px;
  }
}

.tableAnalysis {
  padding-bottom: 20px;
  position: relative;

  .center-title {
    margin-bottom: 20px;
  }

  .exportData {
    position: absolute;
    right: 0px;
    top: 0px;

  }
}
.search {
  display: flex;

  ::v-deep.el-input__inner {
    border-right: none !important;
    border-radius: 4px 0px 0px 0px;
  }

  ::v-deep .el-button--default {
    border-radius: 0px 4px 4px 0px;
    padding: 0px 10px;
  }
}
::v-deep .el-form {
  .el-form-item {
    margin-bottom: 10px !important;
  }
}
</style>
